<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <script src="./js/earthsdk.js"></script>
    <!-- 面板的样式放到css文件内 -->
    <link rel="stylesheet" href="./css/example1.css">
    <title>Cesium地球初始化</title>
    <style>
        html,
        body,
        #app {
            width: 100%;
            height: 100%;
            margin: 0px;
            padding: 0px;
        }

        .btn {
            margin-top: 10px;
            width: 286px;
        }

        .box label {
            padding-right: 10px;
        }

        .box {
            display: flex;
            align-items: center;
        }
    </style>
</head>

<body>
    <div id="app"></div>
    <div id="panel">
        <div class="box">
            <label for="">纯平地形高度</label> <input id="flatHeight" type="number" value="0" onchange="setFlatHeight()">
        </div>
        <button onclick="createPoint()" class="btn">高程测量</button>

    </div>
    <script>
        /** ---------------------------------地球创建------------------------------------**/
        // Vue中引入方式：import { ESObjectsManager } from 'earthsdk3';
        const { ESObjectsManager } = window['EarthSDK3']
        const { ESCesiumViewer } = window['EarthSDK3_Cesium']
        const { ESUeViewer } = window['EarthSDK3_UE']
        const objm = new ESObjectsManager(ESCesiumViewer, ESUeViewer);
        window.g_objm = objm;
        // 监听视口状态
        objm.viewerCreatedEvent.don((viewer) => {
            viewer.flyIn([
                109.02963562468135,
                34.24517722812285,
                595.4392105932077
            ], [
                356.70214753355594,
                -21.984064078384968,
                359.99709817065644
            ], 3);
        });

        // 创建Cesium视口
        const viewer = objm.createCesiumViewer(document.getElementById("app"));
        // 加载Cesium ion的token
        // viewer.ionAccessToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIyZmQzMDI1OC1kMWYyLTQ1ZjEtYTJmNS0yMjY1ZDcxZjEyOTkiLCJpZCI6NjQ3MTgsImlhdCI6MTYyOTQzNDM5M30.m8vkzG05QiAfe6JQ0XPK8z_6KuUVMf_CoSY-YlMnAIg"


        // 通过json创建一个影像图层
        const imageryLayer = objm.createSceneObjectFromJson({
            "id": "9812a65f-0de0-4f7b-b234-809c0c2fb8ef",
            "type": "ESImageryLayer",
            "url": "https://server.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}",
            "maximumLevel": 15
        });

        /**-------------------------------------平球地形-------------------------------**/
        const sceneObject = objm.createSceneObject('ESTerrainLayer')
        sceneObject.name = '平球地形'
        sceneObject.url = 'http://inner.earthsdk.com/layer.json?h=0'

        // 设置平球地形高度
        function setFlatHeight() {
            sceneObject.url = `http://inner.earthsdk.com/layer.json?h=${Number(document.getElementById('flatHeight').value)}`
        }
        /**-------------------------------------点位测量--------------------------------**/
        // 创建一个位置测量对象
        const pointSceneObject = objm.createSceneObject('ESLocationMeasurement')
        // 位置数组
        pointSceneObject.position = [109.03132041021797, 34.25274839985985, 0]

        function createPoint() {
            pointSceneObject.position = [0, 0, 0]
            pointSceneObject.editing = true
        }


    </script>
    <!-- 切换UE和Cesium引擎的组件（Vue） -->
    <div id="root">
        <switch-engine :objm="objm"></switch-engine>
    </div>
    <!-- Vue文件 -->
    <script src="./js/vue.global.js"></script>
    <!-- 切换UE和Cesium的组件 -->
    <script src="./js/switchEngineCom.js"></script>
</body>

</html>